package cate.game.display.msg;

import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBDisplay;
import cate.game.display.po.HeroDisplay;
import cate.game.role.Role;
import cate.game.role.bag.hero.Hero;
import easy.java.dev.note.NoteField;

@ClientMsg(title = "英雄展示生成 の 请求")
public class HeroDisplayBuildReq implements MsgInput {

    @NoteField("英雄的唯一ID")
    public String heroUid;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        final Role role = cc.getRole();
        Hero hero = role.getBag().hero.getItem(this.heroUid);
        if(hero == null) {
            game.notice.message(role, "找不到id="+this.heroUid+"的英雄");
            return;
        }
        HeroDisplay display = HeroDisplay.build(role,hero);
        display = game.facilities.getMongo().heroDisplay.insert(display);
        HeroDisplayBuildResp resp = new HeroDisplayBuildResp();
        resp.heroUid = this.heroUid;
        resp.displayUid = display.uid;
        cc.sendNow(resp);
        game.notice.message(role, "分享成功");
        role.getHistory().action.shareHero();
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBDisplay.HERO_DISPLAY_BUILD_REQ;
    }
}
